#include <stdio.h>
#include <stdlib.h>

void add1(int a1, int b1, int *sum1)
{
	__asm__ volatile (
		"add r4, %1, %2\n"
		"ldr r3, %0\n"
		"str r4, [r3]\n"
		:"=&m"(sum1)
		:"r"(a1), "r"(b1)
		:"cc", "r3", "r4"
	);
}

void add2(int a1, int b1, int *sum1)
{
	__asm__ volatile (
		"add r4, %1, %2\n"
		"str r4, [%0]\n"
		:"=&r"(sum1)
		:"r"(a1), "r"(b1)
		:"cc", "r4"
	);
}

void add3(int a1, int b1, int *sum1, int a2, int b2, int *sum2)
{
	__asm__ volatile (
		"add %[s1], %[a1], %[b1] \n"
		"add %[s2], %[a2], %[b2] \n"
		:[s1]"=&r"(*sum1), [s2]"=&r"(*sum2)
		:[a1]"r"(a1), [b1]"r"(b1), [a2]"r"(a2), [b2]"r"(b2)
		:"cc"
	);
}

int main(int argc, char *argv[])
{
	int sum1;
	int sum2;
	
	add1(1, 3, &sum1);
	printf("add1:%d + %d = %d\n", 1, 3, sum1);
	add2(1, 3, &sum1);
	printf("add2:%d + %d = %d\n", 1, 3, sum1);
	add3(1, 3, &sum1, 4, 5, &sum2);
	printf("add3:%d + %d = %d; %d + %d = %d\n", 1, 3, sum1, 4, 5, sum2);
	return 0;
}